package org.ccay.enumerable.mybatis;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.ccay.enumerable.PlainEnumItem;
import org.ccay.enumerable.exception.NoEnumTypeFoundException;

public class PlainEnumItemTypeHandler<E extends PlainEnumItem> extends BaseTypeHandler<PlainEnumItem> {

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, PlainEnumItem parameter, JdbcType jdbcType)
			throws SQLException {
		if (jdbcType == null) {
			ps.setString(i, parameter.getValue());
		} else {
			ps.setObject(i, parameter.getValue(), jdbcType.TYPE_CODE); 
		}
	}

	@Override
	public PlainEnumItem getNullableResult(ResultSet rs, String columnName) throws SQLException {
		throw new NoEnumTypeFoundException();
	}

	@Override
	public PlainEnumItem getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		throw new NoEnumTypeFoundException();
	}

	@Override
	public PlainEnumItem getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		throw new NoEnumTypeFoundException();
	}
	
}
